package com.jstyle.jclife.view;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.view.ViewGroup;
import android.view.Window;


import com.jstyle.jclife.minterface.DialogDataListener;

import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/4/10.
 */

public  abstract class JstyleDialog extends Dialog {
    protected DialogDataListener dialogDataListener;
    public JstyleDialog(@NonNull Context context) {
        super(context);
        setContentView();
        ButterKnife.bind(this);
    }

    public JstyleDialog(@NonNull Context context, @StyleRes int themeResId) {
        super(context, themeResId);
        setContentView();
        ButterKnife.bind(this);
    }

    protected JstyleDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        setContentView();
        ButterKnife.bind(this);
    }

    protected abstract void setContentView();




    protected void initWidth(int witdh){

        ViewGroup.LayoutParams lay =getWindow().getAttributes();
        lay.width = witdh;
    }
    protected void initHeight(int height){

        ViewGroup.LayoutParams lay =getWindow().getAttributes();
        lay.height = height;
    }
    protected void initGravity(int gravity){
        Window w = getWindow();
        w.setGravity(gravity);
    }
    protected  void initStyle(int style){
        Window w = getWindow();
        w.setWindowAnimations(style);
    }

    public void setDialogDataListener(DialogDataListener listener){
        this.dialogDataListener=listener;
    }
    protected void sendData(String data){
        if(dialogDataListener!=null){
            dialogDataListener.dataListener(data);
        }
    }
    protected void sendData(int position){
        if(dialogDataListener!=null){
            dialogDataListener.dataListener(position);
        }
    }
}
